package com.springcloud.sc.ucpv5.client.commondata.data;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.springcloud.sc.ucpv5.client.commondata.MyUser;

public class GroupDataInfo {

    public GroupDataInfo() {
	groupUserLevel = new HashMap<String, String>();
    }

    // 组内用户排序级别
    public Map<String, String> groupUserLevel = new HashMap<String, String>();

    public void groupUserLevelSet(String nuymber, String level) {
	groupUserLevel.put(nuymber, level);
    }

    public GroupLevelComparator groupLevelComparator =  new GroupLevelComparator();;

    public List sortGroupUser(List children) {
	groupLevelComparator.setGroupUserLevel(groupUserLevel);
	return com.springcloud.sc.ucpv5.client.util.SortUtil.sortList(children, groupLevelComparator);
    }
}

class GroupLevelComparator implements Comparator {
    private Map<String, String> groupUserLevel = new HashMap<String, String>();

    public void setGroupUserLevel(Map<String, String> groupUserLevel) {
	this.groupUserLevel = groupUserLevel;
    }

    public int compare(Object arg0, Object arg1) {
	try {
	    MyUser desc_0 = (MyUser) arg0;
	    MyUser desc_1 = (MyUser) arg1;

	    String level1 = groupUserLevel.get(desc_0.getUserTelNo());
	    String level2 = groupUserLevel.get(desc_1.getUserTelNo());

	    if (level1 == null) {
		level1 = "9999";
	    }
	    if (level2 == null) {
		level2 = "9999";
	    }
	    if (level1 != null && level2 != null) {
		try {
		    return (new Integer(level1)).compareTo(new Integer(level2));
		} catch (Exception e) {
		    // TODO: handle exception
		}
		return level1.compareToIgnoreCase(level2);
	    }
	    return 0;
	} catch (Exception e) {
	    //e.printStackTrace();
	}
	return 0;
    }
}
